package com.hualan.sfzy.controller.psyc;

import com.hualan.sfzy.entity.PsycKnowledge;
import com.hualan.sfzy.service.psyc.PsycKnowledgeService;
import com.hualan.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/psyc")
public class PsycKnowledgeController {
    @Autowired
    private PsycKnowledgeService psycKnowledgeService;

    @GetMapping
    public Result fineById(Integer id) {
        PsycKnowledge psycKnowledge = psycKnowledgeService.findById(id);
        if (psycKnowledge == null) {
            return Result.error("查询成功");
        }
        return Result.success(psycKnowledge);
    }
    @GetMapping("/all")
    public Result findAll(){
        List<PsycKnowledge> list =  psycKnowledgeService.findAll();
        return Result.success(list);
    }
    @GetMapping("/page")
    public Result findPage(PsycKnowledge psycKnowledge, Integer pageNum, Integer pageSize){
        Map<String,Object> map = psycKnowledgeService.findPage(pageNum,pageSize,psycKnowledge);
        return Result.success(map);
    }
    @DeleteMapping("/batch")
    public Result removeBatch(@RequestParam Integer[] ids){
        int count = psycKnowledgeService.removeBatch(ids);
        if(count > 0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    @DeleteMapping()
    public Result remove(@RequestParam Integer id){
        int count = psycKnowledgeService.remove(id);
        if(count > 0){
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    @PostMapping("/add-selective")
    public Result addSelective(@RequestBody PsycKnowledge psycKnowledge){
        int count = psycKnowledgeService.addSelective(psycKnowledge);
        if(count > 0){
            return Result.success("添加成功");
        }
        return Result.error("添加失败");
    }
    @PutMapping
    public Result editSelective(@RequestBody PsycKnowledge psycKnowledge){
        int count = psycKnowledgeService.edit(psycKnowledge);
        if(count > 0){
            return Result.success("修改成功");
        }
        return Result.error("修改失败");
    }
}
